package two;

import java.util.LinkedList;
import java.util.Stack;

public class A024 {
    public static void main(String[] args) {

    }

    //回文链表
    public boolean isPalindrome(ListNode head) {
        //1.使用一个栈，存入一半的链表
        if(head.next==null) return true;
        ListNode slow = head;
        ListNode fast = head;
        Stack<ListNode> stack = new Stack<>();
        while(fast!=null && fast.next!=null) {
            stack.push(slow);
            slow = slow.next;
            fast = fast.next.next;
        }
        //2.比较元素
        if(fast!=null) {//偶数个节点
            slow = slow.next;
        }
//        while (!stack.isEmpty()) {
//            if(stack.pop().val != slow.val) return false;
//            slow = slow.next;
//        }
        return true;
    }

}
